package cn.unknowpupil.init.utils.thread;

import java.util.List;
import java.util.concurrent.Callable;

/**
 * Created at 2020/11/10 by w10g <br>
 * Initialize SunCallable ... <br>
 *
 * @author unknowpupil
 * @since 0.0.1
 */
public class SunCallable implements Callable<Boolean> {

    /**
     * 当前是属于第几段线程
     **/
    private int pageIndex;

    private List<String> list;

    public SunCallable(int pageIndex, List<String> list) {
        this.pageIndex = pageIndex;
        this.list = list;
    }


    @Override
    public Boolean call() throws Exception {
        System.err.println(String.format("pageIndex:%s size:%s", pageIndex, list.size()));
        Boolean result = Boolean.TRUE;
        if (null != list && list.size() > 0) {
            for (String str : list) {
                try {
                    System.out.println(pageIndex + "::::" + str);

                    //调用业务方法
                    handleStr(str);
                } catch (Exception e) {
                    result = Boolean.FALSE;

                }
            }
        }
        return result;
    }

    /**
     * 业务处理
     *
     * @param str
     * @throws InterruptedException
     */
    public void handleStr(String str) throws InterruptedException {
        System.err.println(Thread.currentThread().getName() + str);
        Thread.sleep(1000);
    }




}
